#! -*- encoding: utf-8 -*-
print("""A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.""")
print("")

def getHighestPalindromicNumber(startA, startB):
    highest = 0
    sum = 0
    value = 0
    digits = []
    for i in range(startA, startB):
        for j in range(startA, startB):
            sum = i * j
            value = sum
            digits = []
            while value > 0:
                digits.append(value - (value / 10) * 10)
                value = value / 10
            digits.reverse()

            if isPalindromic(digits):
                if sum > highest:
                    highest = sum
    return highest

def isPalindromic(listOfNumbers):
    length = len(listOfNumbers)
    if length == 0:
        return False

    i = length / 2

    for j in range(i):
        a = listOfNumbers[j]
        b = listOfNumbers[length-1-j]
        if a != b:
            return False

    return True

if __name__ == "__main__":
    # start with 900 to 1000 because every thing else is nonsense
    highest =  getHighestPalindromicNumber(900, 1000)
    print highest
